﻿---@diagnostic disable: trailing-space
local extension = Package:new("moepack_moesp2")
extension.extensionName = "moepack"

Fk:loadTranslationTable{
  ["moepack_moesp2"] = "萌包-SP2",
  ["moesp2"] = "萌SP2",
}


--[[

local jiyuan = General(extension, "moesp__jiyuan", "moe", 4, 4, General.Female)

local emo__dieren = fk.CreateTriggerSkill{
  name = "emo__dieren",
  anim_type = "offensive",
  events = {fk.CardEffectCancelledOut, fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.CardEffectCancelledOut then
        return data.card.trueName == "slash"
      else
        return player:getMark("@emo__dieren") > 0
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.CardEffectCancelledOut then
      self.cost_data = nil
      return true
    else
      local prompt = "#emo__dieren-invoke:"
      if player:getMark("emo__dieren_upgraded") > 0 then
        prompt = "#emo__dieren_up-invoke:"
      end
      if player.room:askForSkillInvoke(player, self.name, nil, prompt..data.to.id.."::"..player:getMark("@emo__dieren")) then
        self.cost_data = {tos = {data.to.id}}
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardEffectCancelledOut then
      room:addPlayerMark(player, "@emo__dieren", 1)
    else
      data.damage = data.damage + player:getMark("@emo__dieren")
      if player:getMark("emo__dieren_upgraded") == 0 then
        room:setPlayerMark(player, "@emo__dieren", 0)
      end
    end
  end,
}
jiyuan:addSkill(emo__dieren)


local emo__chaoyuan = fk.CreateTriggerSkill{
  name = "emo__chaoyuan",
  events = {fk.EnterDying},
  frequency = Skill.Wake,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function (self, event, target, player, data)
    return target == player or (data.damage and data.damage.from == player)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1)
    if player.dead then return end
    room:recover { num = 3, skillName = self.name, who = player, recoverBy = player }
    room:setPlayerMark(player, "emo__dieren_upgraded", 1)
    room:handleAddLoseSkills(player, "emo__guangren|emo__yuanren|emo__lieren")
  end,
}
jiyuan:addSkill(emo__chaoyuan)

local emo__guangren = fk.CreateActiveSkill{
  name = "emo__guangren",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  prompt = "#emo__guangren",
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    room:damage { from = player, to = to, damage = 1, skillName = self.name }
  end,
}
jiyuan:addRelatedSkill(emo__guangren)

local emo__yuanren = fk.CreateTriggerSkill{
  name = "emo__yuanren",
  anim_type = "defensive",
  events = {fk.AfterCardsMove},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    local n = 0
    for _, move in ipairs(data) do
      if move.from == player.id and move.moveReason == fk.ReasonDiscard then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip or info.fromArea == Card.PlayerHand then
            if Fk:getCardById(info.cardId).trueName == "slash" then
              n = n + 1
            end
          end
        end
      end
    end
    if n > 0 then
      self.cost_data = {num = n}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:changeShield(player, self.cost_data.num)
  end,
}
jiyuan:addRelatedSkill(emo__yuanren)

local emo__lieren = fk.CreateTriggerSkill{
  name = "emo__lieren",
  events = {fk.CardUseFinished},
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player and data.card.trueName == "slash" and not player:isKongcheng() then
      local useEvents = player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data[1]
        return use.from == player.id and use.card.trueName == "slash"
      end, Player.HistoryTurn)
      return #useEvents > 0 and useEvents[1].data[1] == data
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local slash = Fk:cloneCard(data.card.name)
    slash.skillName = self.name
    local tos = table.filter(TargetGroup:getRealTargets(data.tos), function (pid)
      local p = room:getPlayerById(pid)
      return not p.dead and not player:isProhibited(p, slash)
    end)
    if #tos == 0 then return end
    local cards = room:askForDiscard(player, 1, 1, false, self.name, true, ".|.|.|hand", "#emo__lieren-card", true)
    if #cards > 0 then
      self.cost_data = {cards = cards, tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data.cards, self.name, player, player)
    room:useVirtualCard(data.card.name, nil, player, table.map(self.cost_data.tos, Util.Id2PlayerMapper), self.name, true)
  end,
}
jiyuan:addRelatedSkill(emo__lieren)


Fk:loadTranslationTable{
  ["moesp__jiyuan"] = "纪源",
  ["#moesp__jiyuan"] = "新纪起源",
  ["designer:moesp__jiyuan"] = "冯世淇",
  
  ["emo__dieren"] = "叠刃",
  [":emo__dieren"] = "每当你使用【杀】被抵消后，获得1枚“叠刃”；每当你造成伤害时，你可以移去所有“叠刃”增加等量伤害值。",
  ["@emo__dieren"] = "叠刃",
  ["#emo__dieren-invoke"] = "叠刃：你可以移去所有“叠刃”，令你对 %src 造成伤害+%arg",
  ["#emo__dieren_up-invoke"] = "叠刃：你可以令你对 %src 造成伤害+%arg",

  ["emo__chaoyuan"] = "超源",
  [":emo__chaoyuan"] = "觉醒技，当你或你令一名角色进入濒死状态时，扣减一点体力上限并回复三点体力，获得技能〖光刃〗，〖源刃〗，〖连刃〗，并升级〖叠刃〗：你造成伤害时不移去“叠刃”。",

  ["emo__guangren"] = "光刃",
  [":emo__guangren"] = "出牌阶段限一次，你可以对一名角色造成1点伤害。",
  ["#emo__guangren"] = "光刃：选择1名角色，你对其造成1点伤害",

  ["emo__yuanren"] = "源刃",
  [":emo__yuanren"] = "锁定技，每当你的一张【杀】被弃置后，你获得1点护甲。",

  ["emo__lieren"] = "连刃",
  [":emo__lieren"] = "你每回合使用的首张【杀】结算后，你可以弃置一张手牌，视为对相同目标使用一张同牌名的【杀】。",
  ["#emo__lieren-card"] = "连刃：你可弃置一张手牌，视为再出一张【杀】！",
}






local moesp__kaluoer = General(extension, "moesp__kaluoer", "moe", 4, 4, General.Female)

local emo__huizhen = fk.CreateTriggerSkill{
  name = "emo__huizhen",
  anim_type = "support",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:usedSkillTimes(self.name, Player.HistoryRound) > 0 or not player:hasSkill(self) then return end
    local mark = target:getMark("@emo__huizhen-turn")
    if mark ~= 0 then
      local hand, hp = table.unpack(table.map(mark, function(e) return tonumber(string.split(e, ":")[2]) end))
      return target:getHandcardNum() == hand and target.hp == hp
    end
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, nil, "#emo__huizhen-invoke:" .. target.id) then
      self.cost_data = {tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@emo__timeMark")
    target:gainAnExtraTurn(false, self.name)
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return not target.dead and target:getMark("@emo__huizhen-turn") == 0
    and player:hasSkill(self, true) and player:usedSkillTimes(self.name, Player.HistoryRound) == 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(target, "@emo__huizhen-turn", {"牌:"..target:getHandcardNum(), "血:"..target.hp})
  end,
}
moesp__kaluoer:addSkill(emo__huizhen)

local emo__shixing = fk.CreateTriggerSkill{
  name = "emo__shixing",
  frequency = Skill.Wake,
  events = { fk.TurnEnd, fk.EnterDying },
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function (self, event, target, player, data)
    if event == fk.TurnEnd then
      return player:getMark("@emo__timeMark") > 2
    else
      return target == player and player:hasSkill("emo__huizhen", true)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EnterDying then
      room:handleAddLoseSkills(player, "-emo__huizhen")
    end
    room:recover { num = 3, skillName = self.name, who = player , recoverBy = player}
    room:handleAddLoseSkills(player, "emo__xinshi|emo__xinhui")
  end,
}

local emo__shixing_delay = fk.CreateTriggerSkill{
  name = "#emo__shixing_delay",
  events = { fk.EventPhaseChanging },
  can_trigger = function(self, event, target, player, data)
    return target == player and data.to == Player.Draw and player:usedSkillTimes("emo__shixing", Player.HistoryGame) > 0
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#emo__shixing-skip")
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@emo__timeMark", 2)
    return true
  end,
}
emo__shixing:addRelatedSkill(emo__shixing_delay)

moesp__kaluoer:addSkill(emo__shixing)

local emo__xinshi = fk.CreateTriggerSkill{
  name = "emo__xinshi",
  events = {fk.EventPhaseStart},
  anim_type = "support",  can_trigger = function(self, event, target, player, data)
    return not target.dead and target.phase == Player.Start and player:hasSkill(self) and player:getMark("@emo__timeMark") > 0
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, nil, "#emo__xinshi-invoke:"..target.id) then
      self.cost_data = {tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(player, "@emo__timeMark")
    if not target:isNude() then
      local cards = room:askForCard(target, 1, 9999, true, self.name, true, ".", "#emo__xinshi-recast")
      if #cards > 0 then
        room:recastCard(cards, target, self.name)
      end
    end
    if not target.dead then
      target:gainAnExtraPhase(Player.Play, true)
    end
  end,
}
moesp__kaluoer:addRelatedSkill(emo__xinshi)


local emo__xinhui = fk.CreateTriggerSkill{
  name = "emo__xinhui",
  events = {fk.EventPhaseStart},
  anim_type = "support",  can_trigger = function(self, event, target, player, data)
    if not target.dead and target.phase == Player.Finish and player:hasSkill(self) and player:getMark("@emo__timeMark") > 0 then
      local ids = {}
      player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data[1]
        if use.from == target.id then
          table.insertTableIfNeed(ids, Card:getIdList(use.card))
        end
        return false
      end, Player.HistoryTurn)
      ids = table.filter(ids, function (id) return player.room:getCardArea(id) == Card.DiscardPile end)
      if #ids > 0 then
        self.cost_data = ids
        return true
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local cards = self.cost_data
    if player.room:askForSkillInvoke(player, self.name, nil, "#emo__xinhui-invoke:"..target.id.."::"..#cards) then
      self.cost_data = {cards = cards, tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:removePlayerMark(player, "@emo__timeMark")
    player.room:obtainCard(target, self.cost_data.cards, true, fk.ReasonPrey, player.id, self.name)
  end,
}
moesp__kaluoer:addRelatedSkill(emo__xinhui)


Fk:loadTranslationTable{
  ["moesp__kaluoer"] = "卡洛儿",
  ["#moesp__kaluoer"] = "甜密时光",
  ["designer:moesp__kaluoer"] = "小七",
  
  ["emo__huizhen"] = "回针",
  [":emo__huizhen"] = "每轮限一次，每当一名角色回合结束时，若其体力值与手牌数等于回合开始时，你可以获得1枚“时”标记并令其获得一个额外回合。",
  ["#emo__huizhen-invoke"] = "回针：你可获得1枚“时”并令 %src 获得一个额外回合",
  ["@emo__huizhen-turn"] = "回针",
  ["@emo__timeMark"] = "时",

  ["emo__shixing"] = "时醒",
  [":emo__shixing"] = "觉醒技，{①任意角色回合结束时，若你有3枚“时”标记；②你进入濒死状态时，失去〖回针〗}：你回复3点体力，并获得技能〖新始〗，〖新回〗，且本局你可跳过摸牌阶段以获得2枚“时”标记。",
  ["#emo__shixing_delay"] = "时醒",
  ["#emo__shixing-skip"] = "时醒：你可跳过摸牌阶段以获得2枚“时”标记",

  ["emo__xinshi"] = "新始",
  [":emo__xinshi"] = "一名角色准备阶段，你可以移去一个“时”标记，令其重铸任意张牌并执行一个额外的出牌阶段。",
  ["#emo__xinshi-invoke"] = "新始：你可弃“时”标记令 %src :重铸任意张牌，并执行出牌阶段",
  ["#emo__xinshi-recast"] = "新始：你可以重铸任意张牌",

  ["emo__xinhui"] = "新回",
  [":emo__xinhui"] = "一名角色的结束阶段，你可以移去一个“时”标记，令其从弃牌堆获得本回合使用过的牌。",
  ["#emo__xinhui-invoke"] = "新回：你可弃“时”标记令 %src 获得本回合使用过的牌(%arg张)",
}


local shark = General(extension, "moesp__specter_shark", "moe", 4, 4, General.Female)

local emo__xueju = fk.CreateTriggerSkill{
  name = "emo__xueju",
  anim_type = "offensive",
  events = { fk.Damage },
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and not data.to.dead
  end,
  on_cost = function (self, event, target, player, data)
    self.cost_data = {tos = {data.to.id}}
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(data.to, "@emo__fear", data.damage)
    local num = player:usedSkillTimes("emo__xuelu", Player.HistoryGame) == 0 and 5 or 3
    player:drawCards(data.to:getMark("@emo__fear"), self.name)
    if data.to:getMark("@emo__fear") >= num and data.to.faceup then
      room:removePlayerMark(data.to, "@emo__fear", num)
      data.to:turnOver()
    end
  end,
}
shark:addSkill(emo__xueju)

local emo__yesha = fk.CreateTriggerSkill{
  name = "emo__yesha",
  anim_type = "offensive",
  events = { fk.TurnStart },
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and table.find(player.room.alive_players, function (p)
      return p ~= player and #p:getCardIds("e") > 0
    end)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(player), function (p) return #p:getCardIds("e") > 0 end)
    local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#emo__yesha-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    local cards = to:getCardIds("e")
    if #cards == 0 then return end
    room:throwCard(cards, self.name, to, player)
    if not to:isKongcheng() then
      room:throwCard(table.random(to:getCardIds("h"), #cards), self.name, to, player)
    end
    if not to.dead and player:usedSkillTimes("emo__xuelu", Player.HistoryGame) > 0 then
      room:damage { from = player, to = to, damage = #cards, skillName = self.name }
    end
  end,
}
shark:addSkill(emo__yesha)

local emo__xuelu = fk.CreateTriggerSkill{
  name = "emo__xuelu",
  frequency = Skill.Wake,
  events = {fk.Deathed},
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  can_wake = function(self, event, target, player, data)
    return data.damage and data.damage.from == player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:usedSkillTimes(self.name, Player.HistoryGame) <= 1 then
      room:handleAddLoseSkills(player, "emo__xueqian|emo__zhenchang")
    else
      room:addPlayerMark(player, "@emo__xuelu-turn", 1)
      room:changeMaxHp(player, 1)
    end
  end,

  refresh_events = {fk.DamageCaused},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@emo__xuelu-turn") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    data.damage = data.damage + player:getMark("@emo__xuelu-turn")
  end,
}
shark:addSkill(emo__xuelu)

local emo__xueqian = fk.CreateTriggerSkill{
  name = "emo__xueqian",
  frequency = Skill.Compulsory,
  events = {fk.AfterDying},
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player.phase ~= Player.NotActive and target ~= player and not target.dead
    and target:getMark("@@emo__xueqian") == 0
  end,
  on_cost = function (self, event, target, player, data)
    self.cost_data = {tos = {target.id}}
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if room:askForChoice(player, {"recover", "#emo__xueqian_prevent:"..target.id}, self.name) == "recover" then
      room:recover { num = 1, skillName = self.name, who = player, recoverBy = player }
    else
      room:setPlayerMark(target, "@@emo__xueqian", 1)
    end
  end,
}

local emo__xueqian_delay = fk.CreateTriggerSkill{
  name = "#emo__xueqian_delay",
  frequency = Skill.Compulsory,
  events = {fk.PreHpRecover},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and target:getMark("@@emo__xueqian") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(target, "@@emo__xueqian", 0)
    room:doAnimate("InvokeSkill", { name = "emo__xueqian", player = player.id, skill_type = "negative" })
    room:sendLog{ type = "#PreventRecover", from = player.id, arg = "emo__xueqian" }
    return true
  end,
}
emo__xueqian:addRelatedSkill(emo__xueqian_delay)

shark:addRelatedSkill(emo__xueqian)

local emo__zhenchang = fk.CreateTriggerSkill{
  name = "emo__zhenchang",
  frequency = Skill.Limited,
  events = {fk.EventPhaseStart},
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player.phase == Player.Finish and target == player
    and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#emo__zhenchang-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:turnOver()
    local targets = room:getOtherPlayers(player)
    room:doIndicate(player.id, table.map(targets, Util.IdMapper))
    for _, p in ipairs(targets) do
      if not p.dead then
        room:damage { from = player, to = p, damage = 1, skillName = self.name }
        room:delay(200)
      end
    end
  end,
}
shark:addRelatedSkill(emo__zhenchang)


Fk:loadTranslationTable{
  ["moesp__specter_shark"] = "夜修鱼",
  ["#moesp__specter_shark"] = "夜世游鲨",
  ["designer:moesp__specter_shark"] = "封世七长久",
  
  ["emo__xueju"] = "血锯",
  [":emo__xueju"] = "锁定技，每当你对其他角色造成伤害后，令其获得伤害值枚“惧”标记，你摸其“惧”数张牌，若其正面朝上且有至少5枚“惧”，移去5枚令其翻面。",
  ["@emo__fear"] = "惧",

  ["emo__yesha"] = "夜鲨",
  [":emo__yesha"] = "回合开始时，你可以弃置一名其他角色装备区中所有牌，并随机弃置其等量张手牌。",
  ["#emo__yesha-choose"] = "夜鲨：选择一名其他角色，弃置其所有装备，弃置其等量张手牌！",

  ["emo__xuelu"] = "血戮",
  [":emo__xuelu"] = "觉醒技，当你击杀一名角色后，获得技能〖血浅〗、〖震场〗，并升级〖夜鲨〗（再对其造成等量伤害）、升级〖血锯〗（5枚改为3枚）。"..
  "<br><b>可多次觉醒，</b>第二次起：增加1点体力上限且本回合造成伤害+1。",
  ["@emo__xuelu-turn"] = "血戮:伤害+",

  ["emo__xueqian"] = "血浅",
  [":emo__xueqian"] = "锁定技，其他角色于你回合内脱离濒死后，你选择回复1点体力或防止其下次回复体力。",
  ["#emo__xueqian_prevent"] = "防止 %src 下次回复体力",
  ["@@emo__xueqian"] = "浅",
  ["#emo__xueqian_delay"] = "血浅",
  ["#PreventRecover"] = "%from 回复体力被 %arg 防止",

  ["emo__zhenchang"] = "震场",
  [":emo__zhenchang"] = "限定技，结束阶段，你可以翻面，并依次对所有其他角色造成1点伤害。",
  ["#emo__zhenchang-invoke"] = "震场：你可以翻面，并依次对所有其他角色造成1点伤害",

  ["$emo__xueju"] = "额呵呵……",
  ["$emo__yesha1"] = "我来自深邃的海洋……",
  ["$emo__yesha2"] = "回归深渊吧！",
  ["$emo__xuelu1"] = "呵呵呵…哈哈……",
  ["$emo__xuelu2"] = "哈哈哈哈！！",
  ["$emo__xueqian"] = "不许逃走。",
  ["$emo__zhenchang1"] = "各位，晚安……",
  ["$emo__zhenchang2"] = "各位，晚安……",
}

local luoweiliu = General(extension, "moesp__luoweiliu", "moe", 4, 4, General.Female)

local emo__wangjing = fk.CreateTriggerSkill{
  name = "emo__wangjing",
  anim_type = "control",
  events = { fk.TurnStart },
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and table.find(player.room.alive_players, function (p)
      return p ~= player and not p:isKongcheng()
    end)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(player), function (p) return not p:isKongcheng() end)
    local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#emo__wangjing-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    local cards = to:getCardIds("h")
    if #cards == 0 then return end
    local x = math.max(0, player.hp)
    local ok_buttons, cancel_button = {}, {"Cancel"}
    if x > 0 then
      table.insert(ok_buttons, "OK")
      if x >= #cards then
        table.insert(cancel_button, 1, "All")
      end
    end
    local chosen, choice = U.askforChooseCardsAndChoice(player, cards, ok_buttons, self.name, "#emo__wangjing-mark:::"..x,
    cancel_button, x > 0 and 1 or 0, x)
    if choice == "All" then
      chosen = cards
    end
    for _, id in ipairs(chosen) do
      room:setCardMark(Fk:getCardById(id), "@@emo__meteor", 1)
    end
  end,

  -- 监测流星标记的移动，应该写在赋予流星标记的技能处
  refresh_events = {fk.AfterCardsMove},
  can_refresh = function (self, event, target, player, data)
    if player ~= player.room.players[1] then return end -- 仅侦测一次
    for _, move in ipairs(data) do
      for _, info in ipairs(move.moveInfo) do
        if Fk:getCardById(info.cardId):getMark("@@emo__meteor") ~= 0 then
          return true
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local map = {}
    for _, move in ipairs(data) do
      for _, info in ipairs(move.moveInfo) do
        if Fk:getCardById(info.cardId):getMark("@@emo__meteor") ~= 0 then
          room:setCardMark(Fk:getCardById(info.cardId), "@@emo__meteor", 0)
          if move.from and (move.moveReason == fk.ReasonUse or move.moveReason == fk.ReasonDiscard) then
            map[tostring(move.from)] = (map[tostring(move.from)] or 0) + 1
          end
        end
      end
    end
    if next(map) ~= nil then
      data.extra_data = data.extra_data or {}
      data.extra_data.emo__meteor = map
    end
  end,
}
luoweiliu:addSkill(emo__wangjing)

local emo__zhuixing = fk.CreateTriggerSkill{
  name = "emo__zhuixing",
  anim_type = "offensive",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      return data.extra_data and data.extra_data.emo__meteor
    end
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    local map = data.extra_data.emo__meteor
    for pid, num in pairs(map) do
      if not player:hasSkill(self) then break end
      local p = room:getPlayerById(tonumber(pid))
      if not p.dead then
        self:doCost(event, p, player, num)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    self.cost_data = {tos = {target.id}}
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(target, "@emo__starFall", data)
    if target:getMark("@emo__starFall") >= 5 then
      room:removePlayerMark(target, "@emo__starFall", 5)
      room:delay(300)
      room:doIndicate(player.id, {target.id})
      room:damage { from = player, to = target, damage = 3, skillName = self.name }
    end
  end,
}
luoweiliu:addSkill(emo__zhuixing)

local emo__xingtu = fk.CreateTriggerSkill{
  name = "emo__xingtu",
  anim_type = "control",
  events = { fk.CardUseFinished },
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase ~= Player.NotActive then
      local cardType = player:getMark("@emo__xingtu-turn")
      if cardType == 0 then
        local useEvents = player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
          local use = e.data[1]
          return use.from == player.id
        end, Player.HistoryTurn)
        if #useEvents == 0 then return false end
        cardType = useEvents[1].data[1].card:getTypeString()
        player.room:setPlayerMark(player, "@emo__xingtu-turn", cardType)
      end
      return cardType == data.card:getTypeString() and table.find(player.room.alive_players, function (p)
        return p ~= player and not p:isKongcheng()
      end) 
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(player), function (p) return not p:isKongcheng() end)
    local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#emo__xingtu-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    local cards = to:getCardIds("h")
    if #cards == 0 then return end
    local card = Fk:getCardById(table.random(cards))
    local isStar = card:getMark("@@emo__meteor") > 0
    room:throwCard(card, self.name, to, player)
    if isStar then
      if to.dead then return end
      room:addPlayerMark(to, "@emo__starFall")
      if to:getMark("@emo__starFall") >= 5 then
        local from = table.find(room:getAlivePlayers(), function (p) return p:hasSkill("emo__zhuixing") end)
        if from then
          room:removePlayerMark(to, "@emo__starFall", 5)
          room:notifySkillInvoked(player, "emo__zhuixing", "offensive", {to.id})
          room:doIndicate(player.id, {to.id})
          room:damage { from = player, to = to, damage = 3, skillName = "emo__zhuixing" }
        end
      end
    else
      if not player.dead then
        player:drawCards(1, self.name)
      end
    end
  end,
}
luoweiliu:addSkill(emo__xingtu)

Fk:loadTranslationTable{
  ["moesp__luoweiliu"] = "洛微流",
  ["#moesp__luoweiliu"] = "观星录图",
  ["designer:moesp__luoweiliu"] = "世世无常",
  
  ["emo__wangjing"] = "望镜",
  [":emo__wangjing"] = "回合开始时，你可以观看一名其他角色的手牌，选择其中至多X张牌标记为“流星”牌（X为你当前体力值）。",
  ["@@emo__meteor"] = "流星",
  ["#emo__wangjing-choose"] = "望镜：你可观看一名其他角色的手牌，并标记为“流星”牌",
  ["#emo__wangjing-mark"] = "选择至多 %arg 张牌标记为“流星”",
  ["All"] = "全部",

  ["emo__zhuixing"] = "坠星",
  [":emo__zhuixing"] = "锁定技，当一名角色使用或弃置一张“流星”牌后，令其获得1枚“坠星”标记；当任意角色有5枚“坠星”标记，移去并对其造成3点伤害。",
  ["@emo__starFall"] = "坠星",

  ["emo__xingtu"] = "星图",
  [":emo__xingtu"] = "你的回合内，每当你使用与本回合第一张牌类型相同的牌后，你可以弃置一名其他角色随机一张手牌，若此牌为“流星”牌，令其获得1枚“坠星”标记；若不为，你摸一张牌。",
  ["#emo__xingtu-choose"] = "星图：你可弃置一名其他角色随机一张手牌",
  ["@emo__xingtu-turn"] = "星图",
}

local foxwish = General(extension, "moesp__foxwish", "moe", 4, 4, General.Female)

local emo__guihuo = fk.CreateTriggerSkill{
  name = "emo__guihuo",
  events = {fk.Damaged, fk.CardUsing, fk.CardResponding},
  frequency = Skill.Compulsory,
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target ~= player and not target.dead then
      if event == fk.Damaged then
        return true
      else
        return target:getMark("@emo__ghostFire") > 0 and not target:isNude()
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    self.cost_data = {tos = {target.id}}
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      local num = (player:usedSkillTimes("emo__yeming", Player.HistoryGame) > 0) and 2 or 1
      room:addPlayerMark(target, "@emo__ghostFire", num)
    else
      local cards = target:getCardIds("he")
      if #cards == 0 then return end
      room:removePlayerMark(target, "@emo__ghostFire")
      room:throwCard(table.random(cards), self.name, target, target)
    end
  end,
}
foxwish:addSkill(emo__guihuo)


local emo__yedeng = fk.CreateTriggerSkill{
  name = "emo__yedeng",
  events = {fk.AfterCardsMove},
  frequency = Skill.Compulsory,
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.moveReason == fk.ReasonDiscard and move.skillName == "emo__guihuo" then
          if #move.moveInfo > 0 then
            self.cost_data = move.moveInfo[1].cardId
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:delay(200)
    local cardId = self.cost_data
    if player:usedSkillTimes("emo__yeming", Player.HistoryGame) > 0 and room:getCardArea(cardId) == Card.DiscardPile then
      room:obtainCard(player, cardId, true, fk.ReasonJustMove, player.id, self.name)
    end
    if player.dead then return end
    room:addPlayerMark(player, "@emo__nightLight")
    local num = player:getMark("@emo__nightLight")
    if num % 3 == 0 then
      player:drawCards(1, self.name)
    end
    if num >= 9 and not player.dead then
      room:setPlayerMark(player, "@emo__nightLight", 0)
      room:changeMaxHp(player, 1)
      room:recover { num = 1, skillName = self.name, who = player, recoverBy = player }
    end
  end,
}
foxwish:addSkill(emo__yedeng)

local emo__yeming = fk.CreateTriggerSkill{
  name = "emo__yeming",
  frequency = Skill.Wake,
  events = {fk.MaxHpChanged},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.num > 0
    and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    player.room:handleAddLoseSkills(player, "emo__nosleep")
  end,
}
foxwish:addSkill(emo__yeming)

-- “不夜”和“布野”重名了……
local emo__nosleep = fk.CreateActiveSkill{
  name = "emo__nosleep",
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  frequency = Skill.Limited,
  card_filter = Util.FalseFunc,
  prompt = "#emo__nosleep",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    for _, p in ipairs(room:getOtherPlayers(player)) do
      local num = p:getMark("@emo__ghostFire")
      if num > 0 then
        room:setPlayerMark(p, "@emo__ghostFire", 0)
        local cards = p:getCardIds("he")
        if #cards > 0 then
          room:delay(200)
          room:throwCard(table.random(cards, num), self.name, p, p)
        end
      end
    end
    local num = player:getMark("@emo__nightLight")
    room:setPlayerMark(player, "@emo__nightLight", 0)
    for i = 1, num do
      local others = room:getOtherPlayers(player, false)
      if #others == 0 then break end
      local to = table.random(others)
      room:delay(500)
      room:doIndicate(player.id, {to.id})
      room:damage { from = player, to = to, damage = 1, skillName = self.name, damageType = fk.FireDamage }
    end
  end,
}
foxwish:addRelatedSkill(emo__nosleep)


Fk:loadTranslationTable{
  ["moesp__foxwish"] = "狐愿",
  ["#moesp__foxwish"] = "夜中行灯",
  ["designer:moesp__foxwish"] = "枫世奇景",
  
  ["emo__guihuo"] = "鬼火",
  [":emo__guihuo"] = "锁定技，每当一名其他角色受到伤害后，令其获得1枚“鬼火”标记：当其使用或打出牌时，移去1枚“鬼火”并随机弃置一张牌。",
  ["@emo__ghostFire"] = "鬼火",

  ["emo__yedeng"] = "夜灯",
  [":emo__yedeng"] = "锁定技，每当牌因〖鬼火〗被弃置后，你获得1枚“夜灯”标记，每获得3枚“夜灯”你摸一张牌，若已有9枚，移除所有“夜灯”，增加一点体力上限并回复一点体力。",
  ["@emo__nightLight"] = "夜灯",

  ["emo__yeming"] = "夜明",
  [":emo__yeming"] = "觉醒技，当你增加体力值上限时，获得技能〖不夜〗，升级〖鬼火〗：令其获得1枚标记改为2枚；升级〖夜灯〗：你获得因〖鬼火〗弃置的牌。",

  ["emo__nosleep"] = "不夜",
  [":emo__nosleep"] = "限定技，出牌阶段，你可以令所有其他角色依次移去所有“鬼火”标记并随机弃置等量的牌，然后你移去所有“夜灯”标记，随机对其他角色分配等量的火焰伤害。",
  ["#emo__nosleep"] = "你可以令所有其他角色移去“鬼火”并弃牌，你移去“夜灯”并对他们造成伤害",

  ["$emo__yeming1"] = "",
  ["$emo__yeming2"] = "",
  ["$emo__nosleep1"] = "",
  ["$emo__nosleep2"] = "",
}

--]]


